package com.jcfk.system.controller;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.web.domain.RetResult;

import com.jcfk.system.domain.dto.SysPortalContentDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.jcfk.system.domain.query.SysPortalContentCatalogQuery;
import com.jcfk.system.domain.dto.SysPortalContentCatalogDTO;
import com.jcfk.system.service.SysPortalContentCatalogService;

import javax.validation.Valid;
import java.util.List;

/**
 * 门户内容目录
 *
 * @author awei
 * @email 522891237@gqq.com
 * @date 2024-03-25
 */
@Api(tags = {"门户内容目录管理"})
@RestController
@RequestMapping("sysPortalContentCataLog")
public class SysPortalContentCatalogController {
    @Autowired
    private SysPortalContentCatalogService sysPortalContentCatalogService;


    /**
     * 查询门户列表
     *
     * @param query
     * @return
     */
    @ApiImplicitParams({@ApiImplicitParam(paramType = "body", dataType = "SysPortalContentCatalogQuery", name = "query", value = "", required = true)})
    @ApiOperation(value = "查询门户列表", notes = "查询门户列表", httpMethod = "POST")
    @PostMapping("getList")
    public RetResult<List<SysPortalContentCatalogDTO>> getList(@RequestBody SysPortalContentCatalogQuery query) {
        List<SysPortalContentCatalogDTO> list = sysPortalContentCatalogService.getList(query);
        return RetResult.ok(list);
    }


    /**
     * 获取门户内容树
     *
     * @param query
     * @return
     */
    @ApiImplicitParams({@ApiImplicitParam(paramType = "body", dataType = "String[]", name = "ids", value = "", required = true)})
    @ApiOperation(value = "获取门户内容树", notes = "获取门户内容树", httpMethod = "POST")
    @PostMapping("getTree")
    public RetResult<List<SysPortalContentCatalogDTO>> getTree(@RequestBody SysPortalContentCatalogQuery query) {
        return RetResult.ok(sysPortalContentCatalogService.getTree(query));
    }


    /**
     * 门户内容目录
     * 根据id 查询详情
     */
    @ApiOperation("查询门户内容目录")
    @GetMapping("/get/{id}")
    public RetResult<SysPortalContentCatalogDTO> get(@PathVariable("id") String id) {
        SysPortalContentCatalogDTO item = sysPortalContentCatalogService.get(id);
        return RetResult.ok(item);
    }


    @ApiOperation("保存门户内容")
    @PostMapping("/save")
    @RequestLogHeader(modular = "门户内容管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid SysPortalContentCatalogDTO sysPortalContentCatalog) {
        // 数据校验


        if (StrUtil.isEmpty(sysPortalContentCatalog.getId())) {
            // 新增
            sysPortalContentCatalogService.insert(sysPortalContentCatalog);
        } else {
            // 更新
            sysPortalContentCatalogService.update(sysPortalContentCatalog);
        }
        return RetResult.ok();

    }

    /**
     * 批量删除门户内容目录
     */
    @ApiOperation("批量删除门户内容目录")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "门户内容目录管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody SysPortalContentCatalogDTO sysPortalContentCatalog) {
        return RetResult.ok(sysPortalContentCatalogService.logicDeleteList(sysPortalContentCatalog));
    }


}
